package com.webchat.chat.web.socketio;
import com.webchat.chat.core.baseEntity.Result;
import com.webchat.chat.core.baseEntity.ResultGenerator;
import com.webchat.chat.core.tools.ChatConstant;
import com.webchat.chat.model.RoomClient;
import com.webchat.chat.service.RoomClientService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.webchat.chat.web.BaseController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by admin on 2018-06-29.
*/
@RestController
@RequestMapping(ChatConstant.CONTROLLER_ROOT_PATH + "/room/client")
public class RoomClientController extends BaseController {
    @Resource
    private RoomClientService roomClientService;

    @PostMapping("/add")
    public Result add(RoomClient roomClient) {
        roomClientService.save(roomClient);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    public Result delete(@RequestParam String id) {
        roomClientService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(RoomClient roomClient) {
        roomClientService.update(roomClient);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    public Result detail(@RequestParam String id) {
        RoomClient roomClient = roomClientService.findById(id);
        return ResultGenerator.genSuccessResult(roomClient);
    }

    @PostMapping("/list")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<RoomClient> list = roomClientService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
}
